import torch
from torch import nn
from gru import Gru


class MLP(nn.Module):
    def __init__(self, input, output):
        super(MLP, self).__init__()
        self.linear = nn.Linear(input, output)
        self.relu = nn.ReLU()

    def forward(self, x):
        return self.relu(self.linear(x))


class Model(nn.Module):
    def __init__(self, features, hidden, output, num_layers):
        super(Model, self).__init__()
        self.mlp = nn.Sequential(MLP(features, hidden * 2), nn.Linear(hidden * 2, 2))
        self.gru = Gru(input_size=features, hidden_size=hidden, output_size=output, num_layers=num_layers)


    def forward(self, x):
        h = self.mlp(x[:, -1, :])
        alpha = self.gru(x)
        result = h[..., 0] * alpha + h[..., 1]
        return result